#ifndef _TASK_H
#define _TASK_H

#include "list.h"

#define TASK_COUNT 32

// ????
#define TASK_STATE_READY     0
#define TASK_STATE_RUNNING   1  
#define TASK_STATE_BLOCKED   2
#define TASK_STATE_SUSPENDED 3

// TCB???
typedef struct {
    int priority;
    int stack_ptr;
    int state;
    list_node_t node;
    char *task_name;
} tcb;

// ??????
extern tcb tasks[TASK_COUNT];
extern int task_count;
extern int cur_task;
extern int task_running;
extern list_t ready_list[6];  // ??????

typedef void (*task_function)(void *param);

// ????
int get_stack(int task_index);
void create_task(task_function f, void *param, char *stack, int stack_len, int priority, const char *name);
void start_task(void);
int is_task_running(void);
void task_add_to_ready(tcb *task);
void task_list_init(void);

void StartTask_asm(int sp, int lr);
int get_next_task(void);
void set_task_stack(int task, int sp);
int scheduler(void);

#endif